home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-02 / wedits22.zip / WECHAT.PAS < prev    next >
Pascal/Delphi Source File  |  1991-08-18  |  6KB  |  245 lines

  1. UNIT WEChat; {$O+}
  2. { -- Chat module for WWIVEdit 2.2
  3.   -- Last Modified 8/13/91
  4.   -- Written By:
  5.   --   Adam Caldwell
  6.   --
  7.   -- This code is limited Public Domain.  See WWIVEDIT.PAS for more details.
  8.   --
  9.   -- Purpose: To do what was previously though un-doable... Create a two
  10.   -- way (split screen) color chat, using the BBS I/O routines (and some
  11.   -- fancy programming).
  12.   --
  13.   -- Known "errors" : If a user hangs up/gets disconnected while in this
  14.   -- chat mode, the computer will lock up.
  15.   --
  16.   -- Proposed fix (as of yet un-implemented):
  17.   --  Install an interrupt handler that will intercept the BBS "DOS"
  18.   --  call that signals that a program should be terminated.  When
  19.   --  this call is seen, restore the Int 9 vector, and let the program
  20.   --  be terminated.  Haven't had time to do this yet.  I tried it once,
  21.   --  but couldn't get it to work... If anyone wants to do this, please
  22.   --  do and send me the solution! :-)
  23.   -- }
  24. {$R-,V-,S-,B-,E-,N-}   { These Optomize things as much as possible }
  25.  
  26. INTERFACE
  27. PROCEDURE Chat(LineLen,ScreenHeight:integer);
  28.  
  29. IMPLEMENTATION
  30.  
  31. USES WEKbd, WEString, WEOutput, WEVars;
  32.  
  33.  
  34.  
  35. PROCEDURE TwoWayChat(Title:string; LineLen,ScreenHeight:integer);
  36. CONST
  37.   MaxPhyLines=50;
  38. TYPE
  39.   stringl=STRING[81];
  40.  
  41. VAR
  42.   ch:char;
  43.   x:integer;
  44.   s:string;
  45.   lastlocal:boolean;
  46.   RemoteTop : integer;
  47.   lx,ly,rx,ry : integer;
  48.   RemoteBottom : integer;
  49.   temp : string;
  50.  
  51.   PROCEDURE WordWrap(VAR s1:StringL; VAR s2:string);
  52.   VAR
  53.     i,x:integer;
  54.   BEGIN
  55.     s2:='';
  56.     x:=length(s1);
  57.     WHILE (x>0) AND (NOT (s1[x]=' ')) DO
  58.       dec(x);
  59.     IF x<>0 THEN
  60.     BEGIN
  61.       s2 := copy(s1,x+1,length(s1)-x);
  62.       prompt(#27+'['+cstr(length(s1)-x)+'D');
  63.       clreol;
  64.       system.delete(s1,x+1,length(s2));
  65.     END;
  66.     writeln;
  67.   END;
  68.  
  69.  
  70.   PROCEDURE IncRY;
  71.   VAR x:integer;
  72.   BEGIN
  73.     inc(ry);
  74.     rx:=1;
  75.     IF ry>RemoteBottom THEN
  76.     BEGIN
  77.       FOR x:=1 TO 4 DO
  78.       BEGIN
  79.         Screen[RemoteTop+x-1].l:=Screen[RemoteBottom-4+x].l;
  80.         gotoxy(1,RemoteTop+x-1);
  81.         write(screen[remoteTop+x-1].l);
  82.         clreol;
  83.       END;
  84.       FOR x:=RemoteTop+4 TO RemoteBottom DO
  85.       BEGIN
  86.         Screen[x].l:='';
  87.         gotoxy(1,x);
  88.         clreol;
  89.       END;
  90.       ry:=RemoteTop+4;
  91.       rx:=1;
  92.     END;
  93.     gotoxy(rx,ry);
  94.   END;
  95.  
  96.   PROCEDURE IncLY;
  97.   VAR x:integer;
  98.   BEGIN
  99.     inc(ly);
  100.     lx:=1;
  101.     IF ly>RemoteTop-2 THEN
  102.     BEGIN
  103.       FOR x:=1 TO 4 DO
  104.       BEGIN
  105.         Screen[x].l:=Screen[RemoteTop-6+x].l;
  106.         gotoxy(1,x);
  107.         write(Screen[x].l);
  108.         clreol;
  109.       END;
  110.       FOR x:=5 TO RemoteTop-2 DO
  111.       BEGIN
  112.         gotoxy(1,x);
  113.         Screen[x].l:='';
  114.         clreol;
  115.       END;
  116.       ly:=5;
  117.       lx:=1;
  118.     END;
  119.     gotoxy(lx,ly);
  120.   END;
  121.  
  122.   PROCEDURE ControlX(l:integer);
  123.   BEGIN
  124.     Screen[l].l:='';
  125.     gotoxy(1,l);
  126.     clreol;
  127.   END;
  128.  
  129.   PROCEDURE ControlW(l:integer; VAR x:integer);
  130.   BEGIN
  131.     WHILE (x>0) AND (screen[l].l[x]<>' ') DO
  132.     BEGIN
  133.       write(#8#32#8);
  134.       dec(x);
  135.     END;
  136.     screen[l].l[0]:=chr(x);
  137.     inc(x);
  138.   END;
  139.  
  140. BEGIN
  141.   FOR x:=1 TO MaxPhyLines DO
  142.     screen[x].l:='';
  143.   clrscr;
  144.   lastlocal:=true;
  145.   RemoteTop:=ScreenHeight DIV 2;
  146.   RemoteBottom := ScreenHeight-2;
  147.   lx:=1; ly:=2;
  148.   rx:=1; ry:=13;
  149.   SeperateLocalInput;
  150.   Ansic('7');
  151.   print('Chat mode:');
  152.   gotoxy(1,RemoteTop-1);
  153.   ansic('3');
  154.   prompt(dup('=',(LineLen-length(title)) div 2)+c4+Title+c3+dup('=',(LineLen-length(title)) div 2));
  155.   ansic('2');
  156.   gotoxy(lx,ly);
  157.   s:='';
  158.   REPEAT
  159.     REPEAT UNTIL KeyPressedL OR KeyPressed;
  160.  
  161.     IF KeyPressedL THEN
  162.     BEGIN
  163.       ch:=readkeyL;
  164.       IF not LastLocal THEN
  165.       BEGIN
  166.         gotoxy(lx,ly);
  167.         ansic('2');
  168.         LastLocal:=true;
  169.       END;
  170.       IF NOT (ch IN [#0..#31]) THEN
  171.       BEGIN
  172.         Screen[ly].l:=Screen[ly].l+ch;
  173.         write(ch);
  174.         inc(lx);
  175.         IF lx>=LineLen THEN
  176.         BEGIN
  177.           wordwrap(screen[ly].l,temp);
  178.           IncLY;
  179.           screen[ly].l:=temp;
  180.           write(temp);
  181.           lx:=length(temp)+1;
  182.         END;
  183.       END
  184.       ELSE IF ch=^X THEN BEGIN ControlX(ly); lx:=1; END
  185.       ELSE IF ch=^W THEN ControlW(ly,lx)
  186.       ELSE IF ch=#13 THEN IncLY
  187.       ELSE IF ch=#27 THEN ch:=#255
  188.       ELSE IF ch=#8 THEN
  189.         IF lx>1 THEN BEGIN
  190.           dec(lx);
  191.           write(#8#32#8);
  192.           delete(Screen[ly].l,lx,1);
  193.         END
  194.     END
  195.     ELSE IF KeyPressed THEN
  196.     BEGIN
  197.       ch:=readkey;
  198.       IF lastlocal THEN
  199.       BEGIN
  200.         gotoxy(rx,ry);
  201.         ansic('1');
  202.         LastLocal:=false;
  203.       END;
  204.       IF NOT (Ch IN [#0..#31,#255]) THEN
  205.       BEGIN
  206.         Screen[ry].l:=Screen[ry].l+ch;
  207.         write(ch);
  208.         inc(rx);
  209.         IF rx>=LineLen THEN
  210.         BEGIN
  211.           wordwrap(screen[ry].l,temp);
  212.           incRY;
  213.           screen[ry].l:=temp;
  214.           write(temp);
  215.           rx:=length(temp)+1;
  216.         END;
  217.       END
  218.       ELSE IF ch=^X THEN BEGIN ControlX(ry); rx:=1; END
  219.       ELSE IF ch=^W THEN ControlW(ry,rx)
  220.       ELSE IF ch=#13 THEN IncRY
  221.       ELSE IF ch=#8 THEN
  222.         IF rx>1 THEN BEGIN
  223.           dec(rx);
  224.           write(#8#32#8);
  225.           delete(screen[ry].l,rx,1);
  226.         END
  227.     END
  228.   UNTIL ch=#255;
  229.  
  230.   MergeLocalInput;
  231. END;
  232.  
  233.  
  234. PROCEDURE Chat(LineLen,ScreenHeight:integer);
  235. { Calls TwoWayChat, and then restores the screen afterwards }
  236. VAR
  237.   ch:char;
  238. BEGIN
  239.   ch:=DisplayColor;
  240.   TwoWayChat('WWIVEdit Two Way Chat',LineLen,ScreenHeight);
  241.   ansic(ch);
  242.   ForcedRedisplay;
  243. END;
  244.  
  245. END.